﻿/* ==============================================================================
* 功能描述：PlayerManager
* 创 建 者：青金石
* 创建日期：2020/5/26 12:01:53
* ==============================================================================*/

using System.Collections.Generic;

public class PlayerManager
{
    //玩家列表
    public static Dictionary<string, Player> players = new Dictionary<string, Player>();

    //玩家是否在线
    public static bool isOnline(string id)
    {
        bool isOnline = players.ContainsKey(id);
        return isOnline;
    }

    // 获取玩家
    public static Player GetPlayer(string id)
    {
        Player player;
        if (players.TryGetValue(id, out player) && player != null)
        {
            return player;
        }
        else
        {
            return null;
        }
    }

    //添加在线玩家
    public static void AddPlayer(string id, Player player)
    {
        if (players.ContainsKey(id))
        {
            return;
        }
        else
        {
            players.Add(id, player);
        }
    }

    //移除下线玩家
    public static void RemovePlayer(string id)
    {
        if (players.ContainsKey(id))
        {
            players.Remove(id);
        }
    }
}